<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class GiftController extends Controller
{
    /**
     * 获取兑奖码
     * @param Request $request
     * @return mixed
     */
    public function getRedeemCode(Request $request){
        $openid = $request->input('openid');
        $redis = $this->initRedis(2);

        $res = $redis->hGetAll($openid);
        //判断兑奖码是否存在
        if(!$res){
            $randStr = $this->getRandStr();
            $redis->hSet($openid, 'redeemCode',$randStr);
            $redis->hSet($openid, 'timestamp', time());
            return $this->success($randStr,'兑奖码生成完成');
        }else{
            return $this->success($res,'兑奖码已存在');
        }



    }
}
